<?php echo form_tag('tallyin/save', array(
  'id'        => 'sf_admin_edit_form',
  'name'      => 'sf_admin_edit_form',
  'multipart' => true,
)) ?>

<?php echo object_input_hidden_tag($tally_in, 'getId') ?>


<?php 
echo link_to_remote('', array('update' => 'list_component', 
  'url' => 'component/listAjax', 
  'loading' => visual_effect('appear', 'indicator'),
  'complete' => visual_effect('fade', 'indicator'). visual_effect('highlight', 'list_component'),
  'position' => 'bottom',
));
?>

<fieldset id="sf_fieldset_none" class="">
<?php
    if ($tally_in->getReviseId()) { ?>
        <input type="hidden" name="tally_in[revise_id]" id="tally_in[revise_id]" value="<?php echo $tally_in->getReviseId() ?>" >
<?}
?>

<div class="form-row">
  <?php echo label_for('tally_in[tallyincode]', __($labels['tally_in{tallyincode}']), 'class="required" ') ?>
  <div class="content<?php if ($sf_request->hasError('tally_in{tallyincode}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('tally_in{tallyincode}')): ?>
    <?php echo form_error('tally_in{tallyincode}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <!--Tien-->
  <?php $default = CommonValues::GenerateAutoNumber('TALLYIN', $tally_in->getTallyincode(), 'TI', 'm')   ?>
   
   <input name="tallyincode" id="tallyincode" value="<?php echo $default ?>" size="15" disabled="disabled" type="text">
   </div>
</div>


<div class="form-row">
  <?php echo label_for('tally_in[type]', __($labels['tally_in{type}']), 'class="required" ') ?>
  <div class="content<?php if ($sf_request->hasError('tally_in{type}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('tally_in{type}')): ?>
    <?php echo form_error('tally_in{type}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <select name="tally_in1[type]" id="tally_in_type1" class="TALLYINTYPE1" disabled="disabled">
    <?php foreach (CommonValues::$gTallyInType['key'] as $key=>$category) { ?>
    <option value="<?php echo $category;  if ($category == $tally_in->getType()) echo '" selected="1'?>"><?php echo $key ?></option>
    <?php } ?>
  </select>

  <input name="tally_in[type]" id="tally_in_type" value="<?php echo $tally_in->getType() ?>" size="15" type="hidden">
  
    </div>
</div>  

<div class="form-row">
  <?php echo label_for('tally_in[created_at]', __($labels['tally_in{created_at}']), '') ?>
  <div class="content<?php if ($sf_request->hasError('tally_in{created_at}')): ?> form-error<?php endif; ?>">
  <?php if ($sf_request->hasError('tally_in{created_at}')): ?>
    <?php echo form_error('tally_in{created_at}', array('class' => 'form-error-msg')) ?>
  <?php endif; ?>

  <?php $value = object_input_date_tag($tally_in, 'getCreatedAt', array (
  'rich' => true,
  'calendar_button_img' => '/sf/sf_admin/images/date.png',
  'control_name' => 'tally_in[created_at]',
)); echo $value ? $value : '&nbsp;' ?>
    </div>
</div>

<div id ="tally_number">
<div class="form-row">
  <?php
  $type = $tally_in->getType()? $tally_in->getType(): 0;
    if ($type == CommonValues::$gTallyInType['key']['Supplier'])
    echo '<label for="tally_in_type" >PO Number:</label>';
    else if ($type==CommonValues::$gTallyInType['key']['Project'])
        echo '<label for="tally_in_type" >Project Number:</label>';
    else if ($type==CommonValues::$gTallyInType['key']['Production'])
        echo '<label for="tally_in_type" >Sale Number:</label>';
    else if ($type==CommonValues::$gTallyInType['key']['Service'])
        echo '<label for="tally_in_type" >DO Number:</label>';
  ?>
  <?

  if ( $type==CommonValues::$gTallyInType['key']['Project']   )
  {

  ?>
    <div class="content">
        <input type = "hidden" name="tally_in[project_id]" id="tally_in_project_id" value="<?echo $tally_in->getProjectId()?>"/>
        <select name="tally_in_tallyno1" id="tally_in_tallyno1" class="tally_in_tallyno1" disabled="disabled" >

     <?
      $c = new Criteria();
      $c->addDescendingOrderByColumn(ProjectPeer::SALENO);
      $projectList = ProjectPeer::doSelect($c);

      $projectId = $tally_in->getProjectId();

      foreach ($projectList as $project)
      {
          $id = $project->getId();
          $selected = "";
          if ($id == $projectId)
                  $selected =" selected='1'";
          echo "<option value='$id' $selected>";
          echo $project->getSaleno().":".$project->getName();
          echo "</option>";
      }
      ?>
        </select>

  </div>

  <?
  }
  else if ($type==CommonValues::$gTallyInType['key']['Production'])
  {

  ?>
    <div class="content">
        <select name="tally_in[tallyno]" id="tally_in_tallyno" class="tally_in_tallyno"  >

     <?
      $c = new Criteria();
      $c->addDescendingOrderByColumn(ProjectPeer::SALENO);
      $projectList = ProjectPeer::doSelect($c);

      foreach ($projectList as $project)
      {
          $id = $project->getId();
          $selected = "";
          if ($id == $tally_in->getTallyno())
                  $selected =" selected='1'";
          echo "<option value='$id' $selected>";
          echo $project->getSaleno().":".$project->getName();
          echo "</option>";
      }
      ?>
        </select>

  </div>

  <?
  }
  else if ($type==CommonValues::$gTallyInType['key']['Supplier'])
  {

  ?>
    <div class="content">
        <? if ($tally_in->getReviseId()) {?>
        <input type = "hidden" name="tally_in[tallyno]" id="tally_in_tallyno" value="<?echo $tally_in->getTallyno()?>"/>
        <select name="tally_in1[tallyno1]" id="tally_in_tallyno1" class="tally_in_tallyn1o" onchange="BuildPOList()" disabled>
        <?}
        else {?>
        <select name="tally_in[tallyno]" id="tally_in_tallyno" class="tally_in_tallyno" onchange="BuildPOList()">
              <?}?>

     <?
      $c = new Criteria();
        $c->addDescendingOrderByColumn(POPeer::PONO);
        $c->add(POPeer::APPROVALSTATUS , CommonValues::$gMRApprovalStatus['key']['Approved']);
        $c->add(POPeer::RECEIVEDSTATUS , CommonValues::$gPOReceivedStatus['key']['Fully Received'], Criteria::NOT_EQUAL);
        $c->add(POPeer::RECEIVEDSTATUS , CommonValues::$gPOReceivedStatus['key']['Revised'], Criteria::NOT_EQUAL);
      $poList = POPeer::doSelect($c);

      foreach ($poList as $po)
      {
          $id = $po->getId();
          $selected = "";
          if ($id == $tally_in->getTallyno())
                  $selected =" selected='1'";
          echo "<option value='$id' $selected>";
          echo $po->getPono().":".$po->getSupplier();
          echo "</option>";
      }
      ?>
        </select>

  </div>

  <?
  }
  else
  {
  ?>
  <input type="text" name ="tally_in[tallyno]" id ="tally_in_tallyno" size="15" value="<? echo $tally_in->getTallyno();?>" >
  <?
  }
  ?>

</div>
</div>        

<?
//BOM
if ($type==CommonValues::$gTallyInType['key']['Project'] ){
    include('_edit_project.php');
}
else if ($type==CommonValues::$gTallyInType['key']['Supplier']){
    include('_edit_supplier.php');
} else
    include('_edit_normal.php');
?>
        
</fieldset>

<?php include_partial('edit_actions', array('tally_in' => $tally_in)) ?>

</form>

<ul class="sf_admin_actions">
      <li class="float-left"><?php if ($tally_in->getId()): ?>
<?php echo button_to(__('delete'), 'tallyin/delete?id='.$tally_in->getId(), array (
  'post' => true,
  'confirm' => __('Are you sure?'),
  'class' => 'sf_admin_action_delete',
)) ?><?php endif; ?>
</li>
  </ul>
